package com.yin.myproject.arithmetic;

import java.util.Arrays;

/**
 * @author Eason
 * @create 2018-04-21 12:51
 **/
public class ShellSorter {
    public static void main(String[] args) {
        int array[] = {94, 12, 34, 76, 26, 9, 0, 37, 55, 76, 37, 5, 68, 83, 90, 37, 12, 65, 76, 49};
        ShellSorter sorter = new ShellSorter();
        int[] sort = sorter.sort(array);
        System.out.println(Arrays.toString(sort));
    }

    private int[] sort(int[] array) {
        int length = array.length;
        int temp;
        for (int increment = length / 2; increment > 0; increment = increment / 2) {
            System.out.println("The step length is : " + increment);
            for (int i = increment; i < array.length; i++) {
                int j = i - increment;
                temp = array[i];
                while (j >= 0 && array[j] > temp) {
                    array[j + increment] = array[j];
                    array[j]=temp;
                    j = j - increment;
                }
            }
            System.out.println(Arrays.toString(array));
        }
        return array;
    }
}
